﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using POS.Framework;

namespace POS
{
    public partial class frmDownloadData : DevExpress.XtraEditors.XtraForm
    {
        bool isDown = false;
        public frmDownloadData()
        {
            InitializeComponent();
        }
        private void frmDownloadData_Shown(object sender, EventArgs e)
        {
            
        }
        private void timerDown_Tick(object sender, EventArgs e)
        {
            if (isDown)
            {
                InfoDown InfoDown = new InfoDown(executeList.ToArray());
                InfoDown.Down();
                isDown = false;
            }
        }
        DownloadModel dlm = null;
        List<DownloadModel> list = new List<DownloadModel>();
        List<string> executeList = new List<string>();
        private void _btnDownload_Click(object sender, EventArgs e)
        {
            if (this._Brand.Checked) 
            {
                dlm = new DownloadModel();
                dlm.ID = list.Count();
                dlm.Name = this._Brand.Text.Trim();
                dlm.PercentValue = 1201;
                list.Add(dlm);
                executeList.Add(this._Brand.Name.Replace("_",""));
            }
            if (this._Category.Checked)
            {
                dlm = new DownloadModel();
                dlm.ID = list.Count();
                dlm.Name = this._Category.Text.Trim();
                dlm.PercentValue = 500;
                list.Add(dlm);
                executeList.Add(this._Category.Name.Replace("_", ""));
            }
            if (this._Product.Checked)
            {
                dlm = new DownloadModel();
                dlm.ID = list.Count();
                dlm.Name = this._Product.Text.Trim();
                dlm.PercentValue = 300;
                list.Add(dlm);
                executeList.Add(this._Product.Name.Replace("_", ""));
            }
            if (this._Provider.Checked)
            {
                dlm = new DownloadModel();
                dlm.ID = list.Count();
                dlm.Name = this._Provider.Text.Trim();
                dlm.PercentValue = 300;
                list.Add(dlm);
                executeList.Add(this._Provider.Name.Replace("_", ""));
            }
            if (this._ProviderContact.Checked)
            {
                dlm = new DownloadModel();
                dlm.ID = list.Count();
                dlm.Name = this._ProviderContact.Text.Trim();
                dlm.PercentValue = 300;
                list.Add(dlm);
                executeList.Add(this._ProviderContact.Name.Replace("_", ""));
            }
            this.gridDownload.DataSource = list;
            isDown = true;
        }
    }
    public class DownloadModel
    {
        public DownloadModel() 
        {
            this.PercentValue = 100;
            this.SortNo = 0;
            this.Remark = "执行中";
        }
        /// <summary>
        /// 
        /// </summary>
        public int ID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 百分比值
        /// </summary>
        public decimal PercentValue { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public decimal SortNo { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string Remark { get; set; }
    }
}